//
//  MPlusEduViewController.m
//  medicineplus
//
//  Created by gufei on 15-5-14.
//  Copyright (c) 2015年 chn_ruby@126.cn. All rights reserved.
//

#import "MPlusEduViewController.h"
#import "MPlusEduplusTableViewCell.h"
#import "MPlusUtils.h"
#import "MPlusDefine.h"
#import "MPlusString.h"

@interface MPlusEduViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSMutableArray *aNewsListArray;
@property (nonatomic, retain) UITableView *aTableView;

@end

@implementation MPlusEduViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self setTabBarResource:kTabBarTitleEdu setImage:kTabBarImageEdu setSelectedImage:kTabBarSelectedImageEdu];
        [self setNavigationTitle:kNavTitleEdu];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _aNewsListArray = [@[@"photo_sample_01",
                         @"photo_sample_02",
                         @"photo_sample_03",
                         @"photo_sample_04",
                         @"photo_sample_05",
                         @"photo_sample_06",
                         @"photo_sample_07",
                         @"photo_sample_08",] mutableCopy];
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-113) style:UITableViewStylePlain];
    // 设置tableView的数据源
    tableView.dataSource = self;
    // 设置tableView的委托
    tableView.delegate = self;
    self.aTableView = tableView;
    self.aTableView.tableHeaderView = [self createFitterView];
    [self.view addSubview:self.aTableView];
    // 去除多余的分割线
    [self setExtraCellLineHidden:_aTableView];
}

- (UIView *)createFitterView {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
    view.backgroundColor = [MPlusUtils colorWithHexString:kBlueColor];
    
    UIButton *categoryBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    categoryBtn.frame = CGRectMake(0, 5, 100, 34);
    [categoryBtn setTitle:@"分类" forState:UIControlStateNormal];
    [categoryBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    categoryBtn.showsTouchWhenHighlighted = YES;
    categoryBtn.tag = 100;
    categoryBtn.backgroundColor=[UIColor clearColor];
//    [categoryBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:categoryBtn];
    
    UIButton *fitterBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    fitterBtn.frame = CGRectMake(SCREEN_WIDTH/2-50, 5, 100, 34);
    [fitterBtn setTitle:@"筛选" forState:UIControlStateNormal];
    [fitterBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    fitterBtn.showsTouchWhenHighlighted = YES;
    fitterBtn.tag = 200;
    fitterBtn.backgroundColor=[UIColor clearColor];
    //    [fitterBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:fitterBtn];
    
    UIButton *sortBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    sortBtn.frame = CGRectMake(SCREEN_WIDTH-5-100, 5, 100, 34);
    [sortBtn setTitle:@"排序" forState:UIControlStateNormal];
    [sortBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    sortBtn.showsTouchWhenHighlighted = YES;
    sortBtn.tag = 300;
    sortBtn.backgroundColor=[UIColor clearColor];
    //    [btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:sortBtn];
    
    return view;
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return _aNewsListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger row = [indexPath row];
    NSString *cellIdentifier = [NSString stringWithFormat:@"%lu", (unsigned long)row];
    MPlusEduplusTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[MPlusEduplusTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                             reuseIdentifier:cellIdentifier];
    }
    
    cell.aImage.image = [UIImage imageNamed:_aNewsListArray[row]];
    cell.aTitle.text = @"中医学课程包";
    cell.aVideoCounts.text = @"视频课件：5课时";
    cell.aExamPaperCounts.text = @"模拟试卷：10套";
    NSString *intro = @"课程简介：课程内容包含：中医及人文医学课件、中医学参考指南书、人文医学指南书";
    [cell.aIntro verticalUpAlignmentWithText:intro maxHeight:40];
    cell.aTimes.text = @"2015-05-20";
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //    DetailViewController *detailVC = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
    //    [self.navigationController pushViewController:detailVC animated:YES];
    //消除cell选择痕迹
    [self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 146;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark Table View setExtraCellLineHidden Methods
- (void)setExtraCellLineHidden: (UITableView *)tableView {
    UIView *view =[ [UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    [tableView setTableHeaderView:view];
}

#pragma mark -
#pragma mark Table View Cell deselect Methods
- (void) deselect {
    [_aTableView deselectRowAtIndexPath:[_aTableView indexPathForSelectedRow] animated:YES];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
